<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    @include('public.h5_head')
    <title>支付</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/pay.css"/>
</head>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
<body>
<div id="box_pay">
    <div class="pay">
        <div class="pay_top">
            <div class="pay_top_left">
                <div class="pay_img">
                    <img src="/img/logo.png" alt="" class="pay_logo" />
                </div>
            </div>
            <div class="pay_top_right"></div>
            <p class="dapin">大品文化</p>
        </div>
        <div class="pay_bottom">
            <p class="pay_words">打开浏览器进入支付环节</p>
            <p class="pay_hint">小贴士：即将进入安全支付页，请放心购买!</p>
        </div>
    </div>
    <div class="pay_mask2 pay_mask" style="display:none;"></div>
    <div class="pay_over" style="display:none;">
        <p class="pay_pass">支付完成</p>
        <p class="pay_ok">确定</p>
    </div>
</div>
</body>

<script>
    /**
     * 与GatewayWorker建立websocket连接，域名和端口改为你实际的域名端口，
     * 其中端口为Gateway端口，即start_gateway.php指定的端口。
     * start_gateway.php 中需要指定websocket协议，像这样
     * $gateway = new Gateway(websocket://0.0.0.0:7272);
     */

        // 服务端主动推送消息时会触发这里的onmessage
    var domain_name = '{{ env('DOMAIN_NAME') }}';
    ws = new WebSocket("wss://"+domain_name+":8282");
    ws.onopen = function() {
//        ws.send('1');
    };
    ws.onmessage = function(e) {
        var data = eval("("+e.data+")");
        var type = data.type || '';
        switch(type){
            // Events.php中返回的init类型的消息，将client_id发给后台进行uid绑定
            case 'init':
                // 利用jquery发起ajax请求，将client_id发给后端进行uid绑定
                $.ajax({
                    url:'/websocket/bindUid',
                    type:'get',
                    data:{info:data.client_id},
                    dataType:'json',
                    success:function(data){
                        if(data.success == true)
                        {

                        }else{
                        }
                    }
                });
                break;
            case  'pay_com':
                $(".pay_over").show();
                $(".pay_mask2").show();
                // alert(data.message);
                break;
            // 当mvc框架调用GatewayClient发消息时直接alert出来
            default :

        }

    };
    //判断当前环境是否为微信内置浏览器
    var ua = navigator.userAgent.toLowerCase();
    var isWeixin = ua.indexOf('micromessenger') != -1;
    if (!isWeixin) {//非微信内置浏览器，说明已经在浏览器中打开了，执行这段逻辑
        window.location.href = '/user/BrowserTransition?order_num={{ $_GET['order_num'] }}';/*-------------------跳转更改-----*/
    }else{//微信浏览器，显示‘在浏览器中打开’图片
        $('#box_pay').show();
    }

    //点击支付完成隐藏
    $(".pay_ok").click(function(){
        $(".pay_over").hide();
        $(".pay_mask2").hide();
        window.location.href = '/UserCenter';/*-------------------跳转更改-----*/
    })
</script>
</html>
